<template>
	<view class="details pB50">
		<!-- <view class="details-top pT10" v-if="choosetype=='2'"><image :src="appointmentDetails.vister_personimg | personimg"></image></view> -->

		<!-- 预约 2,受访1 -->
		<view class="" v-if="choosetype=='2'">
			<view class="intervieweeInformation pT10">
				<p class="bold pB5">受访人信息</p>
				<view class="bg_white">
					<div class="details-top pB10">
						<image :src="appointmentDetails.app_personimg | personimg" mode="aspectFill"></image>
					</div>
				</view>
				<view class="intervieweeInformation-company">受访公司：{{appointmentDetails.app_company_name}}</view>
				<view class="intervieweeInformation-location">受访部门：{{appointmentDetails.app_address}}</view>
				<view class="intervieweeInformation-name">受访人员：{{appointmentDetails.app_user_name}}</view>
				<view class="intervieweeInformation-name">电话号码：{{appointmentDetails.app_mobile}}</view>
				<view class="intervieweeInformation-time">到访开始：{{retime(appointmentDetails.app_visittime)}}</view>
				<view class="intervieweeInformation-time">到访结束：{{retime(appointmentDetails.app_endvisittime)}}</view>

			</view>
			<view class="details-message pT10">
				<p class="bold pB10">访客信息</p>
				<view class="details-message-name">访客姓名：{{appointmentDetails.vister_name}}</view>
				<view class="details-message-sex" v-if="appointmentDetails.vister_sex==1">访客性别：男</view>
				<view class="details-message-sex" v-if="appointmentDetails.vister_sex==2">访客性别：女</view>
				<view class="details-message-number" v-if="appointmentDetails.vister_identitycard | isidcard">
					身份证号：{{appointmentDetails.vister_identitycard | isidcard}}</view>
				<view class="details-message-phone">访客电话：{{appointmentDetails.vister_mobile}}</view>
				<view class="details-message-phone" v-if="appointmentDetails.carnumber">
					车牌号码：{{appointmentDetails.carnumber}}</view>
				<view class="intervieweeInformation-reason">来访缘由：{{appointmentDetails.app_reson}}</view>

				<!-- <view class="intervieweeInformation-reason" v-if="appointmentDetails.followuser">
						<view class="title">
							随访人员
						</view>
						<view class="list">
								<view class="title2 borderb1 flex pT5 pB5">
									<text class='w40 pL5'>姓名</text>
									<text class='w50 pL5'>身份证号码</text>
									<text class='w30 tRight'></text>
								</view>
								<view class="listall">
									<view class="tCenter borderb1 p5 col_999" v-if='appointmentDetails.followuser.length==0'>
										暂无数据
									</view>
									<view class="usrlist borderb1 flex pT5 pB5" v-for="(item,index) in appointmentDetails.followuser">
										<text class='w40 pL5'>{{item.fname}}</text>
										<text class='w50 pL5'>{{item.fidentitycard | isidcard}}</text>
										<text class='w30 tRight'></text>
									</view>
								</view>								
						</view>
					</view> -->
			</view>
		</view>


		<view class="" v-if="choosetype=='1'">
			<view class="intervieweeInformation pT10">
				<p class="bold pB5">邀请人信息</p>
				<view class="bg_white">
					<div class="details-top pB10">
						<image :src="appointmentDetails.app_personimg | personimg" mode="aspectFill"></image>
					</div>
				</view>
				<view class="intervieweeInformation-company">邀请公司：{{appointmentDetails.app_company_name}}</view>
				<view class="intervieweeInformation-location">邀请部门：{{appointmentDetails.app_address}}</view>
				<view class="intervieweeInformation-name">邀请人员：{{appointmentDetails.app_user_name}}</view>
				<view class="intervieweeInformation-name">电话号码：{{appointmentDetails.app_mobile}}</view>
				<view class="intervieweeInformation-time">到访开始：{{retime(appointmentDetails.app_visittime)}}</view>
				<view class="intervieweeInformation-time">到访结束：{{retime(appointmentDetails.app_endvisittime)}}</view>

			</view>
			<view class="details-message pT10">
				<p class="bold pB10">访客信息</p>
				<view class="details-message-name">访客姓名：{{appointmentDetails.vister_name}}</view>
				<view class="details-message-sex" v-if="appointmentDetails.vister_sex==1">访客性别：男</view>
				<view class="details-message-sex" v-if="appointmentDetails.vister_sex==2">访客性别：女</view>
				<view class="details-message-number" v-if="appointmentDetails.vister_identitycard | isidcard">
					身份证号：{{appointmentDetails.vister_identitycard | isidcard}}</view>
				<view class="details-message-phone">访客电话：{{appointmentDetails.vister_mobile}}</view>
				<view class="details-message-phone" v-if="appointmentDetails.carnumber">
					车牌号码：{{appointmentDetails.carnumber}}</view>
				<view class="intervieweeInformation-reason">来访缘由：{{appointmentDetails.app_reson}}</view>

			</view>
		</view>
		<!-- </view> -->
		<view class="statusInformation pT10" v-if="time_streamlist.length != 0">
			<p class="bold pB5">邀请动态</p>
			<view class="status">
				<view class="status-information">到访状态：{{appointmentDetails.m_tips}}</view>
				<view class="" v-if="time_streamlist.length != 0">
					<view class="status-information pB5 " v-for="item in time_streamlist"
						:class="item.type=='2'?'statusEND':''"
						v-if="item.tips=='提交时间'  || item.tips=='受访人员' || item.tips=='访客确认' || item.tips=='访客姓名' || item.tips=='取消原因' || item.tips=='查看时间'">
						<view class="left">{{item.tips}}：</view>
						<view class="right">{{item.value}}</view>
					</view>
				</view>

			</view>

		</view>
		<view class="statusInformation pT10" v-if="time_streamlist[7]">
			<p class="bold pB5">来访动态</p>
			<view class="status">
				<!-- <view class="status-information">到访状态：{{appointmentDetails.m_tips}}</view> -->
				<view class="" v-if="time_streamlist.length != 0">
					<view class="status-information pB5 " v-for="item in time_streamlist"
						:class="item.type=='2'?'statusEND':''"
						v-if="item.tips=='保安扫码' || item.tips=='保安人员' || item.tips=='确认离开' ||item.tips=='取消进入' || item.tips=='取消缘由' ">
						<view class="left">{{item.tips}}：</view>
						<view class="right">{{item.value}}</view>
					</view>
				</view>

			</view>

		</view>
		<view class="statusInformation pT10" v-if="appointmentDetails.healthy_img">
			<p class="bold pB5">点击查看该访客粤康码图片</p>
			<view class="status bg_white" style="padding: 10px;">
				<view class="user-imgshow" @click="previewImg(appointmentDetails.healthy_img)">
					<image :src="appointmentDetails.healthy_img"
						style="width: 200upx; height: 200upx; background-color:  #ebebeb;" />
				</view>
			</view>
		</view>
		<view class="statusInformation pT10" v-if="time_streamlist[10]">
			<p class="bold pB5">到访动态</p>
			<view class="status">
				<!-- <view class="status-information">到访状态：{{appointmentDetails.m_tips}}</view> -->
				<view class="" v-if="time_streamlist.length != 0">
					<view class="status-information pB5" v-for="item in time_streamlist"
						:class="item.type=='2'?'statusEND':''" v-if="item.tips=='扫码接待' || item.tips=='接待人员' ||  item.tips=='接待完成' || item.tips=='接待完成'">
						<view class="left">{{item.tips}}：</view>
						<view class="right">{{item.value}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="btn-button">
			
			<view class="Approved"
				v-if="btnstate!='YES' && appointmentDetails.m_tips != '访客答题中' && appointmentDetails.m_tips != '不同意' || '已逾期' || '访客不来' || '访客不接受到访'"
				@click="backrefresh()">返回</view>
				
			<view class="Approved" v-if="btnstate!='YES' && appointmentDetails.m_tips == '访客答题中' && !canelappchanger " @click="gosubject()">去答题</view>
			<view class="cancel" v-if="appointmentDetails.m_status==7  && appointmentDetails.arrive_status <=1 && choosetype=='1' " @click="refuse()">取消邀请</view>
			<view class="cancel" v-if="appointmentDetails.m_status==7  && appointmentDetails.arrive_status <=1 && choosetype=='2' " @click="refuse2()">取消预约</view>
			<!-- <view class="Approved">审核通过</view>
			<view class="Confirm">确认离开</view> -->
		</view>
		
		<view class="tCenter f16" v-if="controlchanger">
			<view class="f16" v-html="usershowtext"></view>
		</view>
		<!-- 底部导航 -->
		<footernav :pagePath='showstate'></footernav>
		<!-- 加载动画 -->
		<loading v-if="!isloading()"></loading>
	</view>
</template>

<script>
import  {appointmentinfo,appointmentdelete} from '@/common/api/appointment.js';
import {appointmentrefuse,arrivearrive_info} from '../../common/api/appointment.js'; 
import {timestampToTime} from '@/common/common.js'
	export default {
		data() {
			return {
				//状态(1-已不接受,2-已接受,3-已确认)
				canelappchanger: false,
				appointment: '',
				appointmentDetails: [],
				btnstate: '',
				time_streamlist: [],
				item: [],
				choosetype: '2',
				showstate: 'myyuyue',
				btnshowtext: '',
				usershowtext: '',
				controlchanger: true,
			};
		},
		onLoad(options) {
			if (options.btnstate != "") {
				this.btnstate = options.btnstate;
			}
			if (options.appinfo) {
				this.appointmentDetails = JSON.parse(options.appinfo)
			}
			if (options.type) {
				this.choosetype = options.type
				if (options.type == '1') {
					this.showstate = 'myyuyue1';
					uni.setNavigationBarTitle({
						title: '邀请函详情'
					})
				} else {
					this.showstate = 'myyuyue';
					uni.setNavigationBarTitle({
						title: '预约详情'
					})
				}
			}
			if (options.id) {
				appointmentinfo({
					'id': options.id
				}).then(res => {
					if (res.data.code == 400) {
						uni.showModal({
							title: '',
							content: res.data.message,
							showCancel: false,
							confirmText: "确定",
							success: function(res) {
								if (res.confirm) {
									uni.reLaunch({
										url: '/pages/user/user'
									});
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return;
					}
					this.appointmentDetails = res.data.data.appointment_details;
					this.time_streamlist = res.data.data.time_stream;
					this.appointment = res.data.data;
					this.item = res.data.data.meetinginfo;

					console.log("m_status" + this.appointmentDetails)
					if (this.appointmentDetails.m_status == 0) {
						this.controlchanger = false;
					} else if (this.appointment.appointment_details.m_status == 1) {
						// var text='您正在访问...';
						var text = '您已完成本次来访<br>祝您生活愉快';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} else if (this.appointmentDetails.m_status == 2) {
						var text = '本次到访时间已过期<br>如需来访，请重新联系受访人。';
						this.controlchanger = true;
						this.usershowtext = text;
						return;

					} else if (this.appointmentDetails.m_status == 12) {
						var text = '访客不同意到访<br>如需来访，请重新联系受访人。';
						this.controlchanger = true;
						this.usershowtext = text;
						return;

					} else if (this.appointmentDetails.m_status == 3) {
						var text = '本次邀请已过期<br>如需来访，请重新联系受访人。';
						this.controlchanger = true;
						this.usershowtext = text;
						return;

					} else if (this.appointmentDetails.m_status == 4) {
						var text = '受访人暂停本次邀请<br>请重新联系！';
						this.controlchanger = true;
						this.usershowtext = text;
						return;

					} else if (this.appointmentDetails.m_status == 9) {
						var text = '您不接受本次邀请<br>如需来访，请重新联系受访人';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} else if (this.appointmentDetails.m_status == 6) {
						// var text='您已经接受本次邀请<br>请如期安排。';
						var text = '您已经接受邀请<br>请等待受访人确认';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					}
					else if(this.appointmentDetails.m_status == 7 &&this.appointmentDetails.m_tips == "访问中") {
						var text = '您已进行访问<br>离开请受访人扫码签离';
						// var text='您已经接受邀请<br>请等待受访人确认';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} 
					else if(this.appointmentDetails.m_status == 7 &&this.appointmentDetails.m_tips == "保安放行") {
						var text = '您已进入公司<br>请找到受访人让受访人扫码签到';
						// var text='您已经接受邀请<br>请等待受访人确认';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} 
					else if(this.appointmentDetails.m_status == 7 &&this.appointmentDetails.m_tips == "待离开") {
						var text = '您已完成本次访问<br>离开公司请出示二维码让保安扫码放行';
						// var text='您已经接受邀请<br>请等待受访人确认';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} 
					else if(this.appointmentDetails.m_status == 7) {
						var text = '受访人正在等待您的来访<br>请您如约而至。';
						// var text='您已经接受邀请<br>请等待受访人确认';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} else if (this.appointmentDetails.m_status == 8) {
						var text = '您的修改已发送给受访人<br>请等待确认';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} else if (this.appointmentDetails.m_status == 5 && this.appointmentDetails.arrive_status == 5) {
						var text = '保安拒绝您进入<br>如需来访请联系受访人';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} else if (this.appointmentDetails.m_status == 5) {
						var text = '受访人已取消本次邀请<br>如需来访请联系受访人';
						this.controlchanger = true;
						this.usershowtext = text;
						return;	
					} else if (this.appointmentDetails.m_status == 10) {
						var text = '您的修改已发送给受访人<br>请等待确认';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} else if (this.appointmentDetails.m_status == 11) {
						var text = '您已经接受邀请<br>请等待受访人确认';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} else if (this.appointmentDetails.m_status == 13) {
						var text = '请进行相关答题';
						this.controlchanger = true;
						this.usershowtext = text;
						return;
					} 
					if (res.data.data.time_stream) {
						console.log(res.data.data.time_stream)

						console.log("访客" + res.data.data)
					} else {
						console.log('234')
					}

					if (this.appointmentDetails.m_status == 0 && this.appointmentDetails.arrive_status == 0) {
						this.canelappchanger = true;
					} else if (this.appointmentDetails.m_status == 6 && this.appointmentDetails.arrive_status ==
						0) {
						this.canelappchanger = true;
					} else if (this.appointmentDetails.m_status == 7 && this.appointmentDetails.arrive_status ==
						0) {
						this.canelappchanger = true;
					}
				})
			}
			// if(this.appointmentDetails.appointment_status == 1){
			// 	this.canelappchanger = true;
			// }



			// if(this.appointmentDetails.meeting_status == 0){
			// 	this.canelappchanger = true;
			// }
			// if(this.appointmentDetails.auditing == 1){
			// 	this.canelappchanger = true;
			// }
			// var app_visittimeon=Number(this.appointmentDetails.app_visittime)*1000;
			// if(app_visittimeon> (Date.parse(new Date())/1000)){
			// 	this.canelappchanger = true;
			// }
			console.log(this.appointmentDetails);

		},
		onShow() {
			this.showdata();
		},
		methods: {
			showdata() {

			},
			previewImg(logourl) {
				if (logourl) {
					let _this = this;
					let imgsArray = [];
					imgsArray[0] = logourl
					uni.previewImage({
						current: 0,
						urls: imgsArray
					});
				}
			},
			// addrefuse(){
			// 	appointmentrefuse({refusereson:"123",id:this.appointmentDetails.id}).then(res=>{
			// 		console.log(res)
			// 	})
			// }
			refuse() {
				let that=this
				uni.navigateTo({
					url: '/pages/yaoqing/invitationRefuse?id='+this.appointmentDetails.id+'&choosetype=cvis&skipstate=c_adu&type=2',
				});
			},
			refuse2() {
				let that=this
				uni.navigateTo({
					url: '/pages/yaoqing/invitationRefuse?id='+this.appointmentDetails.id+'&choosetype=cvis&skipstate=c_adu&type=1',
				});
			},
			gosubject() {
				let details = {
					companyid: this.appointmentDetails.companyid,
					appointmentid: this.appointmentDetails.id,
					meeting_code: '',
					type: this.appointmentDetails.type + 'yq'
				}
				uni.reLaunch({
					url: "/pages/subject/problem?details=" + encodeURIComponent(JSON.stringify(details))
				});
			},
			retime(time) {
				return timestampToTime(time)
			},
			/*检查状态*/
			checkstatus(e) {
				// console.log(this.getlist[e])
				let iteminfo = this.appointmentDetails;
				if (iteminfo.m_status == 0) {
					return '待访问';
				} else if (iteminfo.m_status == 1) {
					return '已访问';
				} else if (iteminfo.m_status == 2) {
					return '已逾期';
				} else if (iteminfo.m_status == 3) {
					return '已逾期';
				} else if (iteminfo.m_status == 4) {
					return '已暂停';
				} else if (iteminfo.m_status == 5) {
					return '不接受';
				} else if (iteminfo.m_status == 6) {
					return '已接受';
				} else if (iteminfo.m_status == 7) {
					return '已审核';
				} else if (iteminfo.m_status == 8) {
					return '待审核';
				} else if (iteminfo.m_status == 9) {
					return '审核不过';
				} else if (iteminfo.m_status == 10) {
					return '待审核';
				} else if (iteminfo.m_status == 11) {
					return '待确认';
				} else if (iteminfo.m_status == 12) {
					return '已取消';
				} else if (iteminfo.m_status == 13) {
					return '待答题';
				}
				// let timestamp = (new Date()).valueOf();
				// let app_visittimeon=iteminfo.app_visittime*1000;
				// 			console.log(iteminfo.app_visittime<timestamp)
				// /*状态判断---*/
				// //先判断总开关
				// switch(iteminfo.appointment_status){
				// 	case 1:
				// 		return '已访问'
				// 	case 2:
				// 		return '已逾期'
				// 	case 3:
				// 		return '逾期完成'
				// }
				// if(iteminfo.auditing==0){
				// 	return '待审核';
				// }else if(iteminfo.auditing==2){
				// 	return '审核不通过'
				// }
				// if(iteminfo.appointment_status == 0 ){

				// 	if(iteminfo.meeting_status ==2 || iteminfo.meeting_status ==3){
				// 		switch(iteminfo.arrive_status){
				// 			case 1:
				// 				// return '状态(1-到达，2-保安放行，3-到达指定位置，4-离开，5-保安不接受)'
				// 				return '已到达'
				// 			case 2:
				// 				return '已接受'
				// 			case 3:
				// 				return '访问中'
				// 			case 4:
				// 				return '已到达'
				// 			case 5:
				// 				return '已完成'
				// 		}
				// 	}

				// 	if(iteminfo.meeting_status == 1 ){return '已不接受'}
				// }
				// if(iteminfo.app_visittime<timestamp){
				// 	switch(iteminfo.appointment_status){
				// 		case 1:
				// 		return '已访问'
				// 		case 0:
				// 		return '待访问'
				// 		case 4:
				// 		return '已暂停'
				// 		default:
				// 		return '待审核'
				// 	}
				// 	// return '已逾期';
				// }
				// switch(iteminfo.status) {
				//      case 1:
				//         return '已不接受';
				//         break;
				//      case 2:
				//         return '已接受';
				//         break;
				//      case 3:
				//         return '已确认';
				//         break;
				//      default:
				//         return '已完成';
				// } 
			},
		}
	}
</script>

<style lang="scss" scoped>
	.details {
		color: rgba(80, 80, 80, 1);
		font-size: 15px;
		width: 100%;
		background-color: #efeff4;

		.details-top {
			width: 80px;
			height: 80px;
			left: 148px;
			top: 105px;
			font-size: 117px;
			color: rgba(153, 153, 153, 1);
			// border: 1px solid;
			margin: auto;
			margin-top: 10px;


		}

		.details-top image {
			height: 80px;
			width: 80px;
			position: absolute;
			background: #fff;
			border-radius: 50%;
		}

		.details-message {
			width: 95%;
			margin: auto;

			uni-view {
				margin: 0px 0;
				padding: 10px;
				background-color: #fff;
				border-bottom: 1px solid #eee;
			}
		}

		.intervieweeInformation {
			width: 95%;
			margin: auto;

			uni-view {
				margin: 0px 0;
				padding: 10px;
				background-color: #fff;
				border-bottom: 1px solid #eee;
			}
		}

		.statusInformation {
			width: 95%;
			margin: auto;

			.status-information {
				display: flex;
				margin: 0px 0;
				padding: 5px 10px;
				background-color: #fff;
				border-bottom: 1px solid #eee;

				.right {
					margin-left: 0px;
				}
			}

			.statusEND {
				padding-bottom: 10px;
				border-bottom: 1px solid #9e9e9e;
			}
		}

		.btn-button {
			display: flex;
			width: 70%;
			margin: 0 auto;
			justify-content: space-around;
			margin: 10px auto;

			uni-view {
				color: rgba(255, 255, 255, 1);

				border-radius: 18px;
				// font-size: 11px;
				padding: 5px 20px;
			}

			.cancel {
				background-color: rgba(212, 48, 48, 1);
			}

			.Approved {
				background-color: rgba(42, 130, 228, 1);
			}

			.Confirm {
				background-color: rgba(128, 128, 128, 1);
			}
		}
	}
</style>
